package cn.cqie.attendance.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {

    public static Date formatDate(String pattern, Date date) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(pattern);
            sdf.setLenient(false);
            return sdf.parse(sdf.format(date));
        } catch (ParseException e) {
            System.out.println("日期转化异常: DateUtil 15行");
            return null;
        }
    }

    public static String formatDateToString(String pattern, Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        sdf.setLenient(false);
        return sdf.format(date);
    }

    public static Date getNowFormatDate(String pattern) throws ParseException {
        return formatDate(pattern, new Date());
    }
}
